package com.monitor.controller;


import com.alibaba.fastjson.JSONArray;
import com.monitor.entity.ErpBidataList;
import com.monitor.service.ErpBidataListService;
import com.monitor.service.ErpBidataService;
import com.monitor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 车辆BI表 前端控制器
 * </p>
 *
 * @author LX
 * @since 2018-09-12
 */
@RestController
@RequestMapping("/erpBidata")
@Api(description="BI管理")
public class ErpBidataController {
	@Autowired
	private ErpBidataService erpBidataService;
	@Autowired
	private ErpBidataListService erpBidataServiceList;
	
	@RequestMapping("/selBiData")
	@ApiOperation("获取BI数据列表")
	@ApiImplicitParam(name = "cs", value = "关键字", required = false, dataType = "String", paramType = "query")
	public Result<List<List<String>>> selBiData(String cs,Integer userId){
		return erpBidataService.selBiData(userId,cs);
	}
	
	@RequestMapping("/toUpdateBiDate")
	@ApiOperation("获取车辆的接口信息")
	@ApiImplicitParam(name = "id", value = "BI的ID", required = false, dataType = "int", paramType = "query")
	public Result<List<ErpBidataList>> toUpdateBiDate(int id){
		return erpBidataService.toUpdateBiDate(id);
	}
	
	@RequestMapping("/updateBidata")
	@ApiOperation("修改bi接口数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "bi的ID拼接串(,号分割)", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "values", value = "值的拼接串(,号分割)", required = false, dataType = "int", paramType = "query")
    })
	public Result<Boolean> updateBidata(String carPlate,String ids, String values){
		return erpBidataService.updateBidata(carPlate,ids, values);
	}
	@RequestMapping("/updateBiDatas")
	@ApiOperation("修改bi接口数据重写版本")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "ids", value = "bi的ID拼接串(,号分割)", required = false, dataType = "int", paramType = "query"),
//            @ApiImplicitParam(name = "values", value = "值的拼接串(,号分割)", required = false, dataType = "int", paramType = "query")
    })
	public Result<Boolean> updateBiDatas(String json){
        Result<Boolean> result=new Result<>();
	    try{
            ArrayList<ErpBidataList> erpBidataLists = new ArrayList<>(JSONArray.parseArray(json, ErpBidataList.class));

            result.setData(erpBidataServiceList.updateBatchById(erpBidataLists));
        }catch(Exception e){
        	e.printStackTrace();
        }
        return result;
	}

	@RequestMapping("/selectByCarId")
	@ApiOperation("查询bilist数据")
	@ApiImplicitParam(name = "carPlate", value = "车牌号", required = false, dataType = "String", paramType = "query")
	public Result<List<Map<String, String>>> selectByCarId(String carPlate){
		return erpBidataService.selectByCarId(carPlate);
	}
}

